package com.hna.iot.common.utils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class CardUtil {
	/** 
     * 通过身份证号获取性别年龄
     *  
     * @return 
     * @throws Exception 
     */  
    public static Map<String, Object> getCarInfo(String CardCode)throws Exception {  
        Map<String, Object> map = new HashMap<String, Object>();  
        String year = CardCode.substring(6).substring(0, 4);  
        String month = CardCode.substring(10).substring(0, 2);
        String day=CardCode.substring(12).substring(0,2); 
        String sex;  
        if (Integer.parseInt(CardCode.substring(16).substring(0, 1)) % 2 == 0) {
            sex = "女";  
        } else {  
            sex = "男";  
        }  
        Date now = new Date();  
        String date = DateUtils.getDate10(now); 
        String fyear = date.substring(0, 4);// 当前年份  
        String fyue = date.substring(5, 7);// 月份  
        String fday=date.substring(8,10);  
        int age = 0;  
        if (Integer.parseInt(month) <= Integer.parseInt(fyue)) { // 当前月份大于用户出身的月份表示已过生  
            age = Integer.parseInt(fyear) - Integer.parseInt(year) + 1;  
        } else {// 当前用户还没过生  
            age = Integer.parseInt(fyear) - Integer.parseInt(year);  
        }  
        map.put("sex", sex);  
        map.put("age", age);  
        return map;  
    }  
	
}
